{extend name="index_layout"/}
{block name="main"}
<div class="layui-card">
    <div class="layui-card-header">党员管理</div>
    <div class="layui-card-body">

        <div class="layui-fluid" >
            <form method="post" action="{:url('admin/PartMember/excelIn')}" class="form-signin" enctype="multipart/form-data" >
                <input name="excel" type="file" class="form-control">
                <button class="layui-btn layui-btn-sm">导入党员信息</button>
            </form>
        </div>
        <div class="layui-form" style="margin-top: 20px;">
            <div class="temTable layui-fluid">
                <div class="temTable-member-list layui-fluid">
                    手机号：
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="mobile" name=mobile" >
                    </div>
                    身份证号：
                    <div class="layui-inline">
                        <input type="text" class="layui-input" id="idCard" name=idCard" >
                    </div>

                    <button class="layui-btn search" data-type="reload">搜索</button>
                </div>
            </div>
            <table class="layui-hide" id="table" lay-filter="table"></table>

            <script type="text/html" id="toolbarDemo">
                <div class="layui-btn-container">
                    <a class="layui-btn layui-btn-sm" href="{:url('PartMember/add')}">添加党员</a>
                </div>
            </script>
            <script type="text/html" id="barTool">
                <!--<a class="layui-btn layui-btn-xs layui-btn-danger layui-btn-disabled">不可操作</a>-->
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="freeze">删除</a>
            </script>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['table','laydate','form'], function() {
        var table = layui.table,
            $ = layui.$
            ,laydate = layui.laydate;

        //日期时间范围
        laydate.render({
            elem: '#addtime'
            ,type: 'datetime'
            ,range: true
        });

        table.render({
            elem: '#table',
            toolbar: '#toolbarDemo',
            url: '{:url("admin/PartMember/index")}',
            cols: [
                [
                    { field: 'id', width: 80, title: 'ID'},
                    { field: 'user_id', width: 80, title: 'USERID'},
                    { field: 'real_name', width: 120, title: '真实姓名'},
                    { field: 'zhibu', width: 300, title: '所在支部'},
                    { field: 'card_id', width: 200, title: '身份证号码' },
                    { field: 'sex', width: 80, title: '性别' },
                    { field: 'nation',width: 80, title: '民族' },
                    { field: 'bron_date',width: 120, title: '出生日期' },
                    { field: 'educational',width: 120, title: '学历' },
                    { field: 'person_type',width: 120, title: '人员类别' },
                    { field: 'rudang_date',width: 120, title: '入党时间' },
                    { field: 'zhuanzheng_date',width: 120, title: '转正党员时间' },
                    { field: 'work_place',width: 120, title: '工作岗位' },
                    { field: 'mobile',width: 120, title: '手机号' },
                    { field: 'phone',width: 120, title: '固定电话号码' },
                    { field: 'address',width: 200, title: '家庭住址' },
                    { field: 'status',width: 80, title: '党员状态' },
                    { fixed: 'right', width: 160, title: '操作', toolbar: '#barTool' }
                ]
            ],
            id: 'testReload',
            page: {}
        });

        //监听行工具事件
        table.on('tool(table)', function(obj) {
            var data = obj.data;
            //console.log(obj);
            if (obj.event === 'freeze') {
                layer.confirm('确定刪除这个用户？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/partMember/del")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }else if (obj.event === 'edit') {
                window.open('{:url("admin/partMember/add")}' + "?id=" + data.id, '_self')
            }else if(obj.event === 'return'){
                layer.confirm('确定恢复这个用户？', { icon: 3, title: '提示' }, function(index) {
                    layer.close(index);
                    $.post('{:url("admin/member/reUser")}', { 'id': data.id }, function(data) {
                        if (data.code == 1) {
                            if (data.url) {
                                layer.msg(data.msg + ' 页面即将自动跳转~');
                            } else {
                                layer.msg(data.msg);
                            }
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                } else {
                                    location.reload();
                                }
                            }, 1500);
                        } else {
                            layer.msg(data.msg);
                            setTimeout(function() {
                                if (data.url) {
                                    location.href = data.url;
                                }
                            }, 1500);
                        }

                    });
                });
            }
        });


        var $ = layui.$, active = {
            reload: function () {
                var mobile = $("#mobile").val();
                var idCard = $("#idCard").val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
//                        key: {
                        mobile: mobile,
                        idCard: idCard
//                        }
                    }
                });
            }
        };
        $('.temTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


    });
</script>
{/block}